package myjava.algorithm.leetcode;

class Min_Stack {
	
	class ListNodeWithMin {
	    int val;
	    int min;
	    ListNodeWithMin next;
	    ListNodeWithMin(int x) {
	        val = x;
	        next = null;
	    }
	}
	
	ListNodeWithMin head = null;
	
    public void push(int x) {
		if (head == null) {
			head = new ListNodeWithMin(x);
			head.min = x;
		} else {
			ListNodeWithMin newNode = new ListNodeWithMin(x);
			newNode.next = head;
			head = newNode;
			head.min = Math.min(head.next.min, x);
		}
    }

    public void pop() {
        if(head == null) return;
        
        head = head.next;
    }

    public int top() {
    	if(head == null) return 0;
    	
        return head.val;
    }

    public int getMin() {
    	return head == null ? 0 : head.min;
    }
}

public class MinStack {
	public static void main(String[] args)
	{
		
	}
}
